(setq inhibit-startup-message t)
(setq byte-compile-warnings t)

;; load-path
(add-to-list 'load-path (expand-file-name "examyes" user-emacs-directory))

;; ELPA (Emacs Lisp Package Archive )
(when (>= emacs-major-version 24)
  (require 'package)
  (add-to-list
   'package-archives
   '("melpa" . "http://melpa.org/packages/")
   t)
  ;; (add-to-list
  ;;  'package-archives
  ;;  '("marmalade" . "http://marmalade-repo.org/packages/")
  ;;  t)
  (package-initialize))

;; insert-tab
(defun examyes-insert-tab ()
  (interactive)
  (insert-tab))
(define-key global-map (kbd "C-<tab>") 'examyes-insert-tab)

;; windmove
(global-set-key (kbd "S-<down>") 'windmove-down)
(global-set-key (kbd "S-<up>") 'windmove-up)
(global-set-key (kbd "S-<left>") 'windmove-left)
(global-set-key (kbd "S-<right>") 'windmove-right)

;; newline
(global-set-key (kbd "C-<return>") 'newline)

;; text-scale
(global-set-key (kbd "<C-kp-add>") 'text-scale-increase)
(global-set-key (kbd "<C-kp-subtract>") 'text-scale-decrease)

;; ibuffer
(global-set-key (kbd "C-x C-b") 'ibuffer)

;; beginning/end of buffer
(global-set-key (kbd "C-c a") 'beginning-of-buffer)
(global-set-key (kbd "C-c e") 'end-of-buffer)

;; next/previous buffer
(define-key global-map (kbd "<M-right>") 'next-buffer)
(define-key global-map (kbd "<M-left>") 'previous-buffer)

;; isearch
;;(global-set-key [(control s)] 'isearch-forward-regexp)
;;(global-set-key [(control r)] 'isearch-backward-regexp)

;; reduce/enlarge window
(defun examyes-reduce-window ()
  (interactive)
  (enlarge-window -4))

(defun examyes-enlarge-window ()
  (interactive)
  (enlarge-window 4))

(defun examyes-reduce-window-horizontally ()
  (interactive)
  (enlarge-window-horizontally -4))

(defun examyes-enlarge-window-horizontally ()
  (interactive)
  (enlarge-window-horizontally 4))

(define-key global-map (kbd "<C-kp-2>") 'examyes-reduce-window)
(define-key global-map (kbd "<C-kp-8>") 'examyes-enlarge-window)
(define-key global-map (kbd "<C-kp-4>") 'examyes-reduce-window-horizontally)
(define-key global-map (kbd "<C-kp-6>") 'examyes-enlarge-window-horizontally)


;; server
(require 'server)
(unless (server-running-p) (server-start))
(add-hook 'kill-emacs-hook
          (lambda()
            (if (file-exists-p "~/.emacs.d/server/server")
                (delete-file "~/.emacs.d/server/server"))))

;;
;; C mode
;;
(c-add-style "examyes-c-style"
             '("ellemtel"
               (c-basic-offset . 4)))

(defun examyes-c-mode-hook()
  (interactive)
  (define-key c++-mode-map [return] 'newline-and-indent)
  (define-key c-mode-map [return] 'newline-and-indent)
  (modify-syntax-entry ?_  "w" c-mode-syntax-table)
  (modify-syntax-entry ?_  "w" c++-mode-syntax-table)
  ;; (require 'cc-mode)
  ;;  (c-toggle-auto-newline t)
  (c-toggle-hungry-state t)
  ;; (toggle-read-only t)
  ;; (imenu-add-menubar-index)
  ;; (setq c-basic-offset 4)
  (setq tab-width 4)
  ;;  (folding-mode t)
  ;;  (else-mode)
  (setq indent-tabs-mode nil)
  (c-set-style "examyes-c-style")  
  (auto-complete-mode t)
  )
(add-hook 'c-mode-hook 'examyes-c-mode-hook)
(add-hook 'c++-mode-hook 'examyes-c-mode-hook)
(add-hook 'c-mode-common-hook 'examyes-c-mode-hook)

;; recentf, saveplace
(require 'recentf)
(setq recentf-max-saved-items 32)
(recentf-mode 1)
(global-set-key (kbd "C-c C-f") 'recentf-open-files)

(require 'saveplace)
(setq-default save-place t)

;; minibuffer
(minibuffer-electric-default-mode t)
(setq completion-styles '(partial-completion initials))
(setq completion-pcm-complete-word-inserts-delimiters t)
(icomplete-mode t)

;; markdown
(autoload 'markdown-mode "markdown-mode"
  "Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))

;; auto-save
(setq auto-save-default nil)		;不生成 #filename# 文件

;; interlocking
;; http://www.gnu.org/software/emacs/manual/html_node/emacs/Interlocking.html
(setq create-lockfiles nil) ; disable creating .# files

;; backup
(setq make-backup-files t)
(setq backup-directory-alist '(("" . "~/.emacs.d/backup/")))
(setq backup-by-copying t)

;; tab
(setq default-tab-width 4)
(setq-default indent-tabs-mode nil) ; use space for tab

;; line/column number
(global-linum-mode t)

;; paren
(show-paren-mode t)
(setq show-paren-style 'parentheses)

;; selection & mark
(delete-selection-mode t)
(transient-mark-mode t)

;; mode-line
(line-number-mode t)
(column-number-mode t)
(size-indication-mode t)
(setq display-time-24hr-format t)
(setq display-time-interval 10)
(display-time)

;; UI
;;(menu-bar-mode -1)
;;(tool-bar-mode -1)
;;(scroll-bar-mode -1)
(setq scroll-margin 3
      scroll-conservatively 10000)

(setq frame-title-format "emacs - %f")

;; speedbar
;;(global-set-key  [f8] 'speedbar-get-focus)

;; other settings
(setq default-major-mode 'text-mode)
(mouse-avoidance-mode 'animate)
(setq-default which-function-mode t)
(setq suggest-key-bindings 1)
(fset 'yes-or-no-p 'y-or-n-p)
(mouse-avoidance-mode 'animate)
(setq visible-bell t)

(setq uniquify-buffer-name-style 'forward)
(setq-default truncate-lines nil)

(custom-set-variables
 '(face-font-family-alternatives (quote (("Monospace" "courier" "fixed") ("courier" "CMU Typewriter Text" "fixed") ("Sans Serif" "helv" "helvetica" "arial" "fixed") ("helv" "helvetica" "arial" "fixed") ("courier new" "simsun"))))
)
